﻿Imports System.Xml

Public Class Rectangle
	Inherits Child

	Private _MiterLimit As Double?

	Public Property Self As String

	Public Property ContentType As ContentType?

	Public Property StoryTitle As String

	Public Property AllowOverrides As Boolean?

	Public Property FillColor As String

	Public Property FillTint As Double?

	Public Property OverprintFill As Boolean?

	Public Property CornerRadius As Double?

	Public Property StrokeWeight As Double?

	Public Property MiterLimit As Double?
		Get
			Return _MiterLimit
		End Get
		Set(value As Double?)
			If value.HasValue Then
				If value >= 1 And value <= 500 Then
					_MiterLimit = value
				Else
					Throw New ArgumentOutOfRangeException("value", value, "MiterLimit in Rectangle does not support allow value.")
				End If
			End If
		End Set
	End Property

	Public Property EndCap As EndCap?

	Public Property EndJoin As EndJoin?

	Public Property StrokeType As String

	Public Property StrokeCornerAdjustment As StrokeCornerAdjustment?

	Public Property StrokeDashAndGap As String

	Public Property LeftLineEnd As ArrowHead?

	Public Property RightLineEnd As ArrowHead?

	Public Property StrokeColor As String

	Public Property StrokeTint As Double?

	Public Property GradientFillStart As UnitPointType

	Public Property GradientFillLength As Double?

	Public Property GradientFillAngle As Double?

	Public Property GradientStrokeStart As UnitPointType

	Public Property GradientStrokeLength As Double?

	Public Property GradientStrokeAngle As Double?

	Public Property OverprintStroke As Boolean?

	Public Property GapColor As String

	Public Property GapTint As Double?

	Public Property OverprintGap As Boolean?

	Public Property StrokeAlignment As StrokeAlignment?

	Public Property Nonprinting As Boolean?

	Public Property ItemLayer As String

	Public Property Locked As Boolean?

	Public Property LocalDisplaySetting As DisplaySettingOptions?

	Public Property GradientFillHiliteLength As Double?

	Public Property GradientFillHiliteAngle As Double?

	Public Property GradientStrokeHiliteLength As Double?

	Public Property GradientStrokeHiliteAngle As Double?

	Public Property AppliedObjectStyle As String

	Public Property CornerOption As CornerOptions?

	Public Property Visible As Boolean?

	Public Property Name As String

	Public Property TopLeftCornerOption As CornerOptions?

	Public Property TopRightCornerOption As CornerOptions?

	Public Property BottomLeftCornerOption As CornerOptions?

	Public Property BottomRightCornerOption As CornerOptions?

	Public Property TopLeftCornerRadius As Double?

	Public Property TopRightCornerRadius As Double?

	Public Property BottomLeftCornerRadius As Double?

	Public Property BottomRightCornerRadius As Double?

	Public Property ItemTransform As TransformationMatrixType

	Public Property PathGeometry As PathGeometry

	Public Property TextWrapPreference As TextWrapPreference

	Public Property InCopyExportOption As InCopyExportOption

	Public Shared Function ReadXml(reader As XmlReader) As Rectangle
		Dim r As New Rectangle

		If reader.HasAttributes() Then
			r.Self = reader.GetAttribute("Self")
			r.ContentType = Parser.ParseEnum(Of ContentType)(reader.GetAttribute("ContentType"))
			r.StoryTitle = reader.GetAttribute("StoryTitle")
			r.AllowOverrides = Parser.ParseBoolean(reader.GetAttribute("AllowOverrides"))
			r.FillColor = reader.GetAttribute("FillColor")
			r.FillTint = Parser.ParseDouble(reader.GetAttribute("FillTint"))
			r.OverprintFill = Parser.ParseBoolean(reader.GetAttribute("OverprintFill"))
			r.CornerRadius = Parser.ParseDouble(reader.GetAttribute("CornerRadius"))
			r.StrokeWeight = Parser.ParseDouble(reader.GetAttribute("StrokeWeight"))
			r.MiterLimit = Parser.ParseDouble(reader.GetAttribute("MiterLimit"))
			r.EndCap = Parser.ParseEnum(Of EndCap)(reader.GetAttribute("EndCap"))
			r.EndJoin = Parser.ParseEnum(Of EndJoin)(reader.GetAttribute("EndJoin"))
			r.StrokeType = reader.GetAttribute("StrokeType")
			r.StrokeCornerAdjustment = Parser.ParseEnum(Of StrokeCornerAdjustment)(reader.GetAttribute("StrokeCornerAdjustment"))
			r.StrokeDashAndGap = reader.GetAttribute("StrokeDashAndGap")
			r.LeftLineEnd = Parser.ParseEnum(Of ArrowHead)(reader.GetAttribute("LeftLineEnd"))
			r.RightLineEnd = Parser.ParseEnum(Of ArrowHead)(reader.GetAttribute("RightLineEnd"))
			r.StrokeColor = reader.GetAttribute("StrokeColor")
			r.StrokeTint = Parser.ParseDouble(reader.GetAttribute("StrokeTint"))
			r.GradientFillStart = New UnitPointType(reader.GetAttribute("GradientFillStart"))
			r.GradientFillLength = Parser.ParseDouble(reader.GetAttribute("GradientFillLength"))
			r.GradientFillAngle = Parser.ParseDouble(reader.GetAttribute("GradientFillAngle"))
			r.GradientStrokeStart = New UnitPointType(reader.GetAttribute("GradientStrokeStart"))
			r.GradientStrokeLength = Parser.ParseDouble(reader.GetAttribute("GradientStrokeLength"))
			r.GradientStrokeAngle = Parser.ParseDouble(reader.GetAttribute("GradientStrokeAngle"))
			r.OverprintStroke = Parser.ParseBoolean(reader.GetAttribute("OverprintStroke"))
			r.GapColor = reader.GetAttribute("GapColor")
			r.GapTint = Parser.ParseDouble(reader.GetAttribute("GapTint"))
			r.OverprintGap = Parser.ParseBoolean(reader.GetAttribute("OverprintGap"))
			r.StrokeAlignment = Parser.ParseEnum(Of StrokeAlignment)(reader.GetAttribute("StrokeAlignment"))
			r.Nonprinting = Parser.ParseBoolean(reader.GetAttribute("Nonprinting"))
			r.ItemLayer = reader.GetAttribute("ItemLayer")
			r.Locked = Parser.ParseBoolean(reader.GetAttribute("Locked"))
			r.LocalDisplaySetting = Parser.ParseEnum(Of DisplaySettingOptions)(reader.GetAttribute("LocalDisplaySetting"))
			r.GradientFillHiliteLength = Parser.ParseDouble(reader.GetAttribute("GradientFillHiliteLength"))
			r.GradientFillHiliteAngle = Parser.ParseDouble(reader.GetAttribute("GradientFillHiliteAngle"))
			r.GradientStrokeHiliteLength = Parser.ParseDouble(reader.GetAttribute("GradientStrokeHiliteLength"))
			r.GradientStrokeHiliteAngle = Parser.ParseDouble(reader.GetAttribute("GradientStrokeHiliteAngle"))
			r.AppliedObjectStyle = reader.GetAttribute("AppliedObjectStyle")
			r.CornerOption = Parser.ParseEnum(Of CornerOptions)(reader.GetAttribute("CornerOption"))
			r.Visible = Parser.ParseBoolean(reader.GetAttribute("Visible"))
			r.Name = reader.GetAttribute("Name")
			r.TopLeftCornerOption = Parser.ParseEnum(Of CornerOptions)(reader.GetAttribute("TopLeftCornerOption"))
			r.TopRightCornerOption = Parser.ParseEnum(Of CornerOptions)(reader.GetAttribute("TopRightCornerOption"))
			r.BottomLeftCornerOption = Parser.ParseEnum(Of CornerOptions)(reader.GetAttribute("BottomLeftCornerOption"))
			r.BottomRightCornerOption = Parser.ParseEnum(Of CornerOptions)(reader.GetAttribute("BottomRightCornerOption"))
			r.TopLeftCornerRadius = Parser.ParseDouble(reader.GetAttribute("TopLeftCornerRadius"))
			r.TopRightCornerRadius = Parser.ParseDouble(reader.GetAttribute("TopRightCornerRadius"))
			r.BottomLeftCornerRadius = Parser.ParseDouble(reader.GetAttribute("BottomLeftCornerRadius"))
			r.BottomRightCornerRadius = Parser.ParseDouble(reader.GetAttribute("BottomRightCornerRadius"))
			r.ItemTransform = TransformationMatrixType.Parse(reader.GetAttribute("ItemTransform"))
		End If

		While reader.Read()
			Select Case reader.Name
				Case "Properties"
					While reader.Read()
						Select Case reader.Name
							Case "PathGeometry"
								r.PathGeometry = PathGeometry.ReadXml(reader)
							Case "Properties"
								If reader.NodeType = XmlNodeType.EndElement Then Exit While
							Case Else
								If reader.NodeType = XmlNodeType.Element Then
									Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "Rectangle - Properties")
								End If
						End Select
					End While
				Case "TextWrapPreference"
					r.TextWrapPreference = TextWrapPreference.ReadXml(reader)
				Case "InCopyExportOption"
					r.InCopyExportOption = InCopyExportOption.ReadXml(reader)
				Case "Rectangle"
					If reader.NodeType = XmlNodeType.EndElement Then
						Exit While
					End If
				Case Else
					If reader.NodeType = XmlNodeType.Element Then
						Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "Rectangle")
					End If
			End Select
		End While

		Return r
	End Function

	Public Overrides Function ToString() As String
		Return "Rectangle - " & Me.Self
	End Function
End Class
